/**
 * jsBridge的Promise封装
 * @param {String} name 方法名
 * @param {*} req 入参
 */
import { JsBridge } from '@/utils/jsBridge'
export default function jsBridge(name, req) {
  return new Promise(resolve => {
    console.log(`[native api]: ${name} start, ${new Date()}`)
    JsBridge.callHandler(name, req, resolve)
  }).then(res => {
    let data
    try {
      data = res
    } catch {
      data = JSON.parse(res)
    }
    console.log(`[native api  response]: ${name} end, ${new Date()}`)
    console.log(data)
    return data
  })
}
